<template>
  <div v-if="model" class="page-hero">
    <div class="topbar d-flex bg-black py-2 px-4 ai-center">
      <img src="../assets/logo.png" alt="" width="30" height="30" />
      <div class="flex-1 ml-3">
        <span class="m-0 text-white mr-3">王者荣耀</span>
        <span class="m-0 text-white">攻略站</span>
      </div>
      <router-link tag="div" to="/" class="text-white">更多英雄<span class="ml-2 fs-xl"> &gt;</span></router-link>
    </div>
    <div class="bg-desc" :style="{'background-image':`url(${model.banner})`}">
      <div class="d-flex content flex-column jc-end text-white p-3 h-100">
        <div>{{model.title}}</div>
        <h2 class="my-2">{{model.name}}</h2>
        <div>{{model.categories.map(v=>v.name).join('/')}}</div>
        <div class="d-flex ai-center pt-1">
          <div class="text-gray-1 d-flex flex-1" v-if="model.scores">
            <div>
              <span class="pr-2">难度</span>
              <span class="text-gray bg-diff circle mr-2">{{model.scores.difficulty}}</span>
            </div>
            <div>
              <span class="pr-2">技能</span>
              <span class="text-gray bg-skill circle mr-2">{{model.scores.skill}}</span>
            </div>
            <div>
              <span class="pr-2">攻击</span>
              <span class="text-gray bg-attack circle mr-2">{{model.scores.attack}}</span>
            </div>
            <div>
              <span class="pr-2">生存</span>
              <span class="text-gray bg-survival circle mr-2">{{model.scores.survival}}</span>
            </div>
          </div>
          <router-link tag="div" to="/" class="text-gray">皮肤:7 <span class="pl-1">&gt;</span></router-link>
        </div>
      </div>
    </div>
    <div class="bg-white pt-3 px-3">
      <div class="d-flex nav pb-2 jc-around">
        <div class="nav-item" :class="{active:navActiveIndex === 0}" @click="navClick1">英雄初识</div>
        <div class="nav-item" :class="{active:navActiveIndex === 1}" @click="navClick2">进阶攻略</div>
      </div>
    </div>
    <swiper ref="list" @slide-change="() => (navActiveIndex = $refs.list.swiper.activeIndex)">
      <swiper-slide>
        <div class="p-3 bg-white">
          <div class="desc d-flex jc-between">
            <div class="d-flex i-btn">
              <i class="iconfont icon-video mr-3 text-primary fs-xxl"></i>
              <div>英雄介绍视频</div>
            </div>
            <div class="d-flex i-btn">
              <i class="iconfont icon-Menu mr-3 text-primary fs-xxl"></i>
              <div>一图识英雄</div>
            </div>
          </div>
          <!-- skill -->
          <div class="skills pt-4" v-if="model.skills">
            <div class="skill-img d-flex jc-around">
              <img :src="item.icon" @click="currentSkillIndex = i" :class="{'active-img': currentSkillIndex === i}"
                style="width:5rem;height:5rem;" v-for="(item,i) in model.skills" :key="i">
            </div>
            <div class="skill-desc mt-4">
              <div class="d-flex">
                <h3 class="m-0 pr-4">{{currentSkill.name}}</h3>
                <div class="text-gray fs-sm">(冷却值:{{currentSkill.cd}} 消耗:{{currentSkill.consume}})</div>
              </div>
              <div class="mt-4 text-back-1 sk-desc">{{currentSkill.description}}</div>
            </div>
          </div>
        </div>

        <hero-card title="出装推荐" icon="Menu">
          <!-- items -->
          <div class="card-body">
            <div class="items1" v-if="model.items1">
              <div class="mt-3 fs-xl">顺风出装</div>
              <div class="d-flex jc-around mt-3">
                <img :src="item.icon" class="item-icon" alt="" v-for="(item,i) in model.items1" :key="i">
              </div>
              <div class="d-flex jc-around">
                <div class="fs-xs mt-2" v-for="(item,i) in model.items1" :key="i">{{item.name}}</div>
              </div>
            </div>
            <div class="items2" v-if="model.items2">
              <div class="mt-3 fs-xl">逆风出装</div>
              <div class="d-flex jc-around mt-3">
                <img :src="item.icon" class="item-icon" alt="" v-for="(item,i) in model.items2" :key="i">
              </div>
              <div class="d-flex jc-around">
                <div class="fs-xs mt-2" v-for="(item,i) in model.items2" :key="i">{{item.name}}</div>
              </div>
            </div>
          </div>
        </hero-card>
        <hero-card title="使用技巧" icon="Menu">
          <p style="line-height:1.5rem;" class="mb-0">{{model.usageTips}}</p>
        </hero-card>
        <hero-card title="对抗技巧" icon="Menu">
          <p style="line-height:1.5rem;" class="mb-0">{{model.battleTips}}</p>
        </hero-card>
        <hero-card title="团战思路" icon="Menu">
          <p style="line-height:1.5rem;" class="mb-0">{{model.teamIdea}}</p>
        </hero-card>
        <hero-card title="英雄关系" icon="Menu">
          <div class="fs-xl py-3">最佳拍档</div>
          <div v-for="(item,i) in model.partner" :key="i" class="d-flex py-1">
            <img :src="item.hero.avatar" style="width:4rem;height:4rem;" alt="">
            <p style="line-height:1.5rem;" class="mt-1 pl-2 mb-0">{{item.description}}</p>
          </div>
        </hero-card>
      </swiper-slide>
      <swiper-slide>
        暂无
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  props: {
    id: { type: String, required: true }
  },
  data () {
    return {
      model: null,
      currentSkillIndex: 0,
      navActiveIndex: 0
    }
  },
  computed: {
    currentSkill () {
      return this.model.skills[this.currentSkillIndex]
    }
  },
  methods: {
    navClick1 () {
      this.$refs.list.swiper.slideTo(0)
      this.navActiveIndex = 0
    },
    navClick2 () {
      this.$refs.list.swiper.slideTo(1)
      this.navActiveIndex = 1
    },
    async fetch () {
      const res = await this.$http.get(`/heroes/${this.id}`)
      this.model = res.data
      console.log(res.data)
    }
  },
  created () {
    this.fetch()
  }
}
</script>

<style lang="scss">
@import '../assets/scss/variables';
.page-hero {
  .bg-desc {
    width: auto;
    height: 50vw;
    background: no-repeat top center;
    background-size: auto 100%;
  }
  .content {
    background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 1));
  }
  .nav {
    border-bottom: 1px solid map-get($colors, 'gray-2');
  }

  .active-img {
    border: 2px solid map-get($colors, 'primary');
    border-radius: 46%;
  }

  .desc .i-btn {
    border: 1px solid map-get($colors, 'light');
    padding: 0.8rem 2.5rem;
    background-color: map-get($colors, 'light-1');
    border-radius: 0.3846rem;
  }

  .circle {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    line-height: 0.9rem;
    font-size: 0.7rem;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  .sk-desc {
    line-height: 1.5rem;
  }

  .items1,
  .items2 {
    .item-icon {
      width: 3.5rem;
      height: 3.5rem;
      border-radius: 50%;
    }
  }
  .items1 {
    border-bottom: 2px solid $border-color;
  }
}
</style>
